package com.sd.service.impl;
import com.jfinal.kit.HttpKit;
import com.jfinal.kit.Kv;
import com.jfinal.template.Engine;
import com.jfinal.template.Template;
import com.sd.common.utils.DateProvider;
import com.sd.cti.server.cmd.AgentLoginCmd;
import com.sd.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;

@Service
public class CustomerServiceImpl implements CustomerService {

    @Value("${picc.customer.serverUrl}")
    private String url;

    @Autowired
    private DateProvider dateProvider;

    @Override
    public void respLogin(HttpServletResponse response,AgentLoginCmd agentLoginCmd) throws Exception {
        String optionTime = dateProvider.formatDatetime(new Date());
        Engine engine = Engine.create("respLogin");
        //engine模版渲染
        engine.setDevMode(true);
        engine.setToClassPathSourceFactory();
        Template template = engine.getTemplate("/resp/respLogin.xml");
        Kv kv = Kv.by("agentId", agentLoginCmd.getAgentId());
        kv.put("station","8009");
        kv.put("optionTime",optionTime);
        kv.put("permission","1213");
        String xml = template.renderToString(kv);
        System.out.println("xml:"+xml);
        String ret = HttpKit.post(url, xml);
    }
}
